const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function (app) {
  // proxy第一个参数为要代理的路由
  // 第二参数中target为代理后的请求网址，changeOrigin是否改变请求头，其他参数请看官网
  app.use(
    //其他书
    createProxyMiddleware("/api/yanan", {
      target: "https://m.xhsd.com",
      secure: false,
      changeOrigin: true,
    }),
    // 购酒网
    createProxyMiddleware("/BtCApi", {
      target: "http://m.gjw.com",
      secure: false,
      changeOrigin: true,
    }),
    //当当网
    createProxyMiddleware(["/ddcategory.php", "/search_ajax.php"], {
      target: "http://search.m.dangdang.com",
      secure: false,
      changeOrigin: true,
    }),
    createProxyMiddleware(["/index.php", "/h5ajax.php"], {
      target: "http://touch.m.dangdang.com",
      secure: false,
      changeOrigin: true,
    }),
    createProxyMiddleware(["/api", "/mapi7"], {
      target: "http://z.dangdang.com",
      secure: false,
      changeOrigin: true,
    }),
    createProxyMiddleware("/cart.php", {
      target: "http://cart.m.dangdang.com",
      secure: false,
      changeOrigin: true,
    }),

    createProxyMiddleware("/review.php", {
      target: "http://product.m.dangdang.com",
      secure: false,
      changeOrigin: true,
    })
  );
};
